/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import request from '@/utils/request';
import { isArray } from 'lodash';
import type { Options } from '@/components/_pages/jdk';

export async function applyUserList(params: any) {
  return request('/jdk/home/applyUserList', {
    method: 'POST',
    data: params,
  });
}

// 备注列表
export async function getRemarkList(params: any): Promise<any> {
  return request('/jdk/home/getRemarkList', {
    method: 'POST',
    data: params,
  });
}

// 添加备注信息
export async function saveRemark(params: any): Promise<any> {
  return request('/jdk/home/saveRemark', {
    method: 'POST',
    data: params,
  });
}

const cMap: any = {};
export async function getChildrenArea(params: any, isLeaf = false): Promise<Options[]> {
  const { id } = params;
  if (cMap[id]) {
    return cMap[id];
  }
  return request('/jdk/Area/getChildArea', {
    method: 'POST',
    data: params,
  }).then(({ data }) => {
    if (data && isArray(data)) {
      cMap[id] = data.map((item) => ({
        label: item.name,
        value: item.code,
        id: item.id,
        pid: item.pid,
        isLeaf,
      }));
      return cMap[id];
    }
    return [];
  });
}
